package com.example.liuliang.recylerviewtest210.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.liuliang.recylerviewtest210.adapter.MyAdapter;
import com.example.liuliang.recylerviewtest210.R;
import com.example.liuliang.recylerviewtest210.bean.ArticleBean;
import com.example.liuliang.recylerviewtest210.iface.ArticleListener;
import com.example.liuliang.recylerviewtest210.model.ArticleModel;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter myAdapter;

    private List<ArticleBean> list = null;
    ArticleListener articleListener=new ArticleListener() {
        @Override
        public void onResponse(List<ArticleBean> beanlist) {
            list=beanlist;
            myAdapter.setList(list);
            myAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(MainActivity.this,"失败："+msg,Toast.LENGTH_SHORT);
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initRecyclerView();

        ArticleModel model=new ArticleModel();
        model.getResulrList("article",1,"rv1l2tidbomann2qn86nln6ur2",articleListener);
    }

    private void initRecyclerView() {
        recyclerView = (RecyclerView) findViewById(R.id.recylerview);
        layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        //list=getData();
        myAdapter = new MyAdapter(this);
        myAdapter.setList(list);
        recyclerView.setAdapter(myAdapter);

    }
}
    /*
    private List<ArticleBean> getData(){

        List<ArticleBean> list=new ArrayList<ArticleBean>();

        ArticleBean articleBean;

        articleBean=new ArticleBean();
        articleBean.setArticleId(1);
        articleBean.setTitle("标题1");
        articleBean.setDescription("a");
        articleBean.setTime("2017-4-18");
        articleBean.setImgid(R.drawable.f1);
        list.add( articleBean);


        articleBean=new ArticleBean();
        articleBean.setArticleId(2);
        articleBean.setTitle("标题2");
        articleBean.setDescription("b");
        articleBean.setTime("2017-4-18");
        articleBean.setImgid(R.drawable.f2);
        list.add( articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(3);
        articleBean.setTitle("标题3");
        articleBean.setDescription("c");
        articleBean.setTime("2017-4-18");
        articleBean.setImgid(R.drawable.f3);
        list.add( articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(4);
        articleBean.setTitle("标题4");
        articleBean.setDescription("d");
        articleBean.setTime("2017-4-18");
        articleBean.setImgid(R.drawable.f4);
        list.add( articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(5);
        articleBean.setTitle("标题5");
        articleBean.setDescription("e");
        articleBean.setTime("2017-4-18");
        articleBean.setImgid(R.drawable.f5);
        list.add( articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(6);
        articleBean.setTitle("标题6");
        articleBean.setDescription("f");
        articleBean.setTime("2017-4-18");
        articleBean.setImgid(R.drawable.f6);
        list.add( articleBean);
        return list;
    }
}*/
